(function(){
	@@include("./common/_infiniteScroll.js")
    @@include("./common/_popWindow.js")
	var $quickList = $(".quick-list");
	var length = $(".current .production-detail").length;
	var height = $quickList.offset().top;
	$(".current>.rank").removeClass("animation");

	$(".attention").on("click",function(){
		var postData={id:"XXX",state:1,type:1},
		    that = $(this),
		    followFlag = 1;
		if($(this).hasClass('favorited')){
			postData.state = 2
			followFlag = 2
		}
		$.ajax({
		  type: 'POST',
		  url: "./lib/fllow.json",
		  data: postData,
		  dataType: 'json',
		  success: function(data){
		  	if(data.code == 200){
		  		if(followFlag == 1){
		  			that.addClass('favorited')
		  		}
		  		if(followFlag == 2){
		  			that.removeClass('favorited')
		  		}
		  	}
		  },
		});
	})
	$(".more").on("click",function(){
		if($(this).hasClass("down")){
			$(this).parent().addClass("div-ellipsis");
			$(this).removeClass("down").text("View More");
		} else {
			$(this).addClass("down").text("Roll Up");
			$(this).parent().removeClass("div-ellipsis");
		}
	})
	$(".view-more").on("click",function(){
		if($(this).hasClass("down")){
			$(this).parent().addClass("detail-ellipsis");
			$(this).removeClass("down").html("View More<i></i>");
		} else {
			$(this).addClass("down").html("Roll Up<i></i>");
			$(this).parent().removeClass("detail-ellipsis");
		}
	})
	$(".rank li,.quick-list li").on("click",function(){
		var index = $(this).index();
		var top  = $(".current .production-detail")[index].offsetTop + 80;
		$("html,body").animate({scrollTop:top},Math.min(300*++index,500));
	})

    $('.attribute li').on("click",function(){
    	if($(this).hasClass('current')) return
    	$(this).addClass('current').siblings().removeClass('current');
    	$(".current .rank").addClass("animation");
    	var index = $('.attribute li').index($(this));
    	length = $(".current .production-detail").length;
    	$('.production').eq(index).addClass('current').siblings(".production").removeClass('current');
    	$('.quick-list').eq(index).addClass('current').siblings(".quick-list").removeClass('current');
    	setTimeout(function(){$(".current>.rank").removeClass("animation");},50);
    })
	$(window).on('scroll',function(){
		if($(window).scrollTop()>height - 80 && $(window).scrollTop()<$('.current>.production-list').offset().top + $('.current>.production-list').height() - $quickList.outerHeight()-80){
	    	if(!$quickList.hasClass("fixed")){
	       		$quickList.addClass("fixed").attr("style","").css({
	       			"right":'auto'
	       		});
	       	}
	    } else {
	    	$quickList.removeClass("fixed").attr("style","");
	    	if($(window).scrollTop()>=$('.current>.production-list').offset().top + $('.current>.production-list').height() - $quickList.outerHeight()-80){
	    		$quickList.css({
	    			"top": $('.left-show').height() - $quickList.outerHeight() - 80,
	    			"left": 0,
	    			"position":"absolute"
	    		});
	    	}
	    }
	    for(var i = length-1;i>=0;i--){
       		if($(window).height()*2/3+$(window).scrollTop()>$(".current .production-detail").eq(i).offset().top && $(window).scrollTop()<$(".current .production-detail").eq(i).offset().top+$(".current .production-detail").eq(i).height()){
       			$(".current.quick-list").find("li").eq(i).addClass("current").siblings().removeClass("current");
       			break;
       		}
       	}
	})
})()
